package com.le.basic.StackAndQueue;

import java.util.Stack;

/**
 * 栈模拟队列
 */
public class Code_04_StackToQueue {
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> help = new Stack<>();

    public void push(int num){
        stack.push(num);
    }

    public int pop(){
        if (stack.isEmpty()){
            throw new RuntimeException("stack is null");
        }
        while (stack.size() >1){
            help.push(stack.pop());
        }
        int res = stack.pop();
        while (!help.isEmpty()){
            stack.push(help.pop());
        }
        return res;
    }


    public static void main(String[] args) {
        Code_04_StackToQueue toQueue = new Code_04_StackToQueue();
        toQueue.push(1);
        toQueue.push(2);
        toQueue.push(3);
        System.out.println(toQueue.pop());
        System.out.println(toQueue.pop());
        System.out.println(toQueue.pop());

    }
}
